using System;
using System.Collections; 
using System.Collections.Generic;
public class HeroPool : BasePool
{
	private static HeroPool instance;
	private Dictionary<int,HeroData> mDataList = new Dictionary<int, HeroData>();
	public HeroPool(){
		instance = this;
	}
	public override IEnumerator Init ()
	{
		HeroData newObj = new HeroData();
		XmlHelper xmlHelper = XmlHelper.GetInstance();
		yield return xmlHelper.StartCoroutine(xmlHelper.getContentsByFiledName(newObj,"Data/Hero"));
		List<object> datas = xmlHelper.alList;
		foreach(object obj in datas){
			newObj = (HeroData)obj;
			mDataList.Add(newObj.id,newObj);
			
			string[] skillStrList = newObj.skillIDByLevel.Split(',');
			newObj.skillIDList = new int[skillStrList.Length];
			for(int i = 0;i < skillStrList.Length;i++){
				newObj.skillIDList[i] = int.Parse(skillStrList[i]);
			}
		}
		yield break;
	}
	public static HeroData GetHero(int id){
		if(instance.mDataList.ContainsKey(id)){
			return instance.mDataList[id];
		}else{
			throw new Exception("Not Find Hero Data,id = "+id+"!");
		}
	}
	public static List<HeroData> GetAllHero(){
		List<HeroData> dataList = new List<HeroData>();
		foreach(HeroData data in instance.mDataList.Values){
			dataList.Add(data);
		}
		return dataList;
	}
}


